<template>
  <!-- recommend vue prop sort
  is v-for v-if v-else-if v-else v-show v-cloak v-pre v-once id ref key slot v-model all-normal-props v-bind v-on v-html v-text-->
  <div>
    <div class="box-wrap">
      <p class="tip">点击完成签约</p>

      <button class="btn-round-blue" @click="handleSign">去签约</button>
      <button v-if="showBack" class="btn-round-blue" @click="goBack">我已签约</button>
    </div>
  </div>
</template>

<script>
import { SIGN_CLOUD_ACCOUNT } from '@/api'
import { getCurrentPageParams } from '@/utils'

export default {
  components: {},
  props: {},
  data () {
    return {}
  },
  computed: {
    showBack () {
      return !!this.$cookie.get('cloud-account-flag')
    }
  },
  watch: {},
  created () {},
  mounted () {},
  onShow () {},
  methods: {
    handleSign () {
      const vm = this

      let params = {
        shopId: vm.$store.state.account.shopId,
        memberType: getCurrentPageParams('memberType')
      }

      SIGN_CLOUD_ACCOUNT(params)
        .then(r => {
          if (r.data.code === '0') {
            vm.$cookie.set('url', r.data.data)
            vm.$cookie.set('cloud-account-flag', true)
            vm.$router.push('/pages/mine/cloud-account/step5/main')
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.error(e)
        })
    },
    goBack () {
      this.$cookie.remove('url')
      this.$router.new('/pages/mine/cloud-account/index/main')
    }
  }
}
</script>

<style lang="scss" scoped>
@import 'static/styles/color.scss';

.box-wrap {
  padding: 15px;
  > .tip {
    font-size: 14px;
    border-left: 5px solid $blue;
    padding-left: 5px;
  }
  > .btn-round-blue {
    margin-top: 30px;
  }
}
</style>
